/*
 * To change this license header, choose License Headers in Project Predicate.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package utfpr.cp.model;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;

/**
 *
 * @author Adriano_2
 */
public class PredicateDAO extends DAO {

    public PredicateDAO(EntityManager em) {
        super(em);
    }
    
    public Predicate getByName(String name) {
        Query q = em.createQuery("SELECT p FROM Predicate p WHERE p.name = :name");
        q.setParameter("name", name);
        try {
            return (Predicate) q.getSingleResult();
        } catch (NoResultException e) {
            //Logger.getLogger(Main.class.getName()).log(Level.OFF, null, e);
        }

        return new Predicate(name, PredicateType.UNKNOWN);
    }
    
    public static PredicateDAO factory() {
        return new PredicateDAO(getEntity());
    }
}
